package com.tgy.crud.converter;

import com.tgy.crud.common.ResultCode;
import com.tgy.crud.domain.User;
import com.tgy.crud.exception.CrudException;
import org.springframework.core.convert.converter.Converter;

public class String2User implements Converter<String, User> {

    @Override
    public User convert(String source) {

        String[] split = source.split("-");
        if (split.length == 2){

          return new User(split[0],split[1]);
        }

        throw  new CrudException(ResultCode.TYPEEXCEPTION);
    }
}
